<div class="form_border user_register">
	<ul class="form_tab">
		<li><a href="<?php echo site_url("user/login")?>">登录</a></li>
		<li class="current"><a href="">注册账号</a></li>
	</ul>
	<div class="clear"></div>
	<form action="" method="post" onsubmit="return is_form_valid(this)">
		<div class="form_row">
			<label class="input_label" for="nickname"><span class="red">*</span> 昵称：</label><input type="text" class="input_text" name="nickname" id="nickname" value="<?php echo empty($nickname) ? '' : $nickname;?>"/>
			<div class="form_tip">6-20个字母、数字、汉字组合</div>
			<div class="form_error"></div>
			<div class="form_right"></div>
			<div class="clear"></div>
		</div>
		<div class="form_row">
			<label class="input_label" for="password"><span class="red">*</span> 密码：</label><input type="password" class="input_text" name="password" id="password"/>
			<div class="form_tip">6-16个字符</div>
			<div class="clear"></div>
			<div class="form_error"></div>
			<div class="form_right"></div>
		</div>
		<div class="form_row">
			<label class="input_label" for="confirm_password"><span class="red">*</span> 确认密码：</label><input type="password" class="input_text" name="confirm_password" id="confirm_password"/>
			<div class="form_tip">6-16个字符</div>
			<div class="clear"></div>
			<div class="form_error"></div>
			<div class="form_right"></div>
		</div>
		<div class="form_row">
			<label class="input_label" for="email"><span class="red">*</span> email：</label><input type="text" class="input_text" name="email" id="email"  value="<?php echo empty($email) ? '' : $email;?>"/>
			<div class="form_tip">请输入您的常用邮箱</div>
			<div class="clear"></div>
			<div class="form_error"></div>
			<div class="form_right"></div>
		</div>
		<div class="form_row">
			<label class="input_label" for="captcha"><span class="red">*</span> 验证码：</label><input type="input" class="input_text" name="captcha" id="captcha"/>
			<div class="right" id="captcha-image"><?php echo $captcha['image'];?></div>
			<div class="clear"></div>
		</div>
		<div class="form_action">
			<input type="checkbox" name="agree_protocal" id="agree_protocal" class="input_checkbox" checked><label>同意《<a target="_blank" class="underline" href="<?php echo site_url("/protocal.html")?>">行动网络服务使用协议</a>》</label>
			<div class="right"><a href="###" id="reset-captcha">看不清，换一换</a></div>
		</div>
		<div class="form_action">
			<input id="user_register_submit" type="submit" class="input_button" value="注册行动网帐号" />
		</div>
	</form>
	<script>
		function is_form_valid(src) {
			var $this = $(src);
			if ($this.find('.form_error').is(':visible') || $('#nickname').val() == '') {
				return false;
			} else {
				return true;
			}
		}
		$('#agree_protocal').click(function(){
			if ($(this).attr('checked')) {
				$('#user_register_submit').attr('disabled', false).removeClass('disabled');
			} else {
				$('#user_register_submit').attr('disabled', true).addClass('disabled');
			}
		});
		$('#reset-captcha').click(function(){
			$.get('/user/reset_captcha',  function(data) {
				$('#captcha-image').html(data);
			})	
		});
		$('#nickname').blur(function(){
			var $this = $(this);
			var nick = $this.val();
			var parent = $this.parent();
			if (nick == '') {
				parent.find('.form_error').html('<div class="error_icon"></div>昵称不能为空').show();
				parent.find('.form_right').hide();
			} else if (!/^[_0-9a-z\u4e00-\u9fa5]+$/gi.test(nick)) {
				parent.find('.form_error').html('<div class="error_icon"></div>昵称不能包括特殊字符').show();
				parent.find('.form_right').hide();
			} else if (nick.length < 6 || nick.length > 20) {
				parent.find('.form_error').html('<div class="error_icon"></div>昵称要在6-20个字符内').show();
				parent.find('.form_right').hide();
			} else {
				$.get('/user/ajax_user_check', {type:'nick', value:nick}, function(data) {
					var data = eval('(' + data + ')');
					if (data.result == '1') {
						parent.find('.form_error').html('<div class="error_icon"></div>此用户名已被使用').show();
						parent.find('.form_right').hide();
					} else {
						parent.find('.form_right').html('<div class="right_icon"></div>此用户名可以使用').show();
						parent.find('.form_error').hide();
					}
				})
			}
		});
		$('#password').blur(function() {
			var $this = $(this);
			var password = $('#password').val();
			var parent = $this.parent();
			if (password == '') {
				parent.find('.form_error').html('<div class="error_icon"></div>密码不能为空').show();
				parent.find('.form_right').hide();
			} else if (password.length < 6 || password.length > 16) {
				parent.find('.form_error').html('<div class="error_icon"></div>密码要在6-16个字符内').show();
				parent.find('.form_right').hide();
			} else {
				parent.find('.form_right').html('<div class="right_icon"></div>密码正确').show();
				parent.find('.form_error').hide();
			}
		});
		$('#confirm_password').blur(function() {
			var $this = $(this);
			var password = $('#password').val();
			var confirm_password = $this.val();
			var parent = $this.parent();
			if (confirm_password == '') {
				parent.find('.form_error').html('<div class="error_icon"></div>密码不能为空').show();
				parent.find('.form_right').hide();
			} else if (confirm_password != password) {
				parent.find('.form_error').html('<div class="error_icon"></div>两次输入密码不一致').show();
				parent.find('.form_right').hide();
			} else {
				parent.find('.form_right').html('<div class="right_icon"></div>确认密码正确').show();
				parent.find('.form_error').hide();
			}
		});
		$('#email').blur(function(){
			var $this = $(this);
			var email = $this.val();
			var parent = $this.parent();
			if (email == '' || !/^([a-zA-Z0-9]+[_|\-|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\-|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/gi.test(email)) {
				parent.find('.form_error').html('<div class="error_icon"></div>邮箱格式不对').show();
				parent.find('.form_right').hide();
			} else {
				$.get('/user/ajax_user_check', {type:'email', value:email}, function(data) {
					var data = eval('(' + data + ')');
					if (data.result == '1') {
						parent.find('.form_error').html('<div class="error_icon"></div>此邮箱已被使用').show();
						parent.find('.form_right').hide();
					} else {
						parent.find('.form_right').html('<div class="right_icon"></div>此邮箱可以使用').show();
						parent.find('.form_error').hide();
					}
				})
			}
		});
	</script>
</div>